<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet"
	href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/web-login.css">
<script src="https://cdn.bootcss.com/jquery/2.1.1/jquery.min.js"></script>
<script
	src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>花市网 - 登   录</title>
</head>
<body>
	<div class="content">
		<div class="top"><p>用户登录</p></div>
		<form id="loginForm" action="${pageContext.request.contextPath}/user/login" method="post">
			<div class="box">
				<span>用户名:&nbsp;&nbsp;</span><input type="text" id="username" name="username"
					placeholder="请使用3-15个中、英文、数字及“-”符号">
			</div>
			<div class="box">
				<span>密&nbsp;&nbsp;&nbsp;码:&nbsp;&nbsp;&nbsp;</span><input type="password" id="password" name="password"
					placeholder="6-20个大小写英文字母、符号或数字">
			</div>
			<button type="button" class="btn btn-danger btn-lg" onclick="loginUser()">登录</button>
		</form>
		<a class="forget_password" href="#" onclick="alert('请联系开发人员')">忘记密码</a><br>
	</div>
</body>
<script type="text/javascript">
function loginUser() {
	//输入校验
	if($("#username").val() == ""){
		alert("请输入用户名称");
		$("#username").focus();
		return;
	}
	if($("#password").val() == ""){
		alert("请输入用户密码");
		$("#password").focus();
		return;
	}
	if($("#username").val() != "" && $("#password").val() != ""){
		$.get("${pageContext.request.contextPath}/user/login/username",{"username":$("#username").val(),"password":$("#password").val()},function(data){
			if(data.user != null){
				//提交表单
				$('#loginForm').submit();
				return;
			}
			alert("用户名或密码错误，请重新输入");
			return;
			
		});
	}
	
}
</script>
</html>